package com.study.controller;

import com.study.blogsearchpojo.entity.Blog;
import com.study.service.SearchFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class IndexController {
    @Autowired
    public SearchFeignService searchFeignService;

    @RequestMapping("/")
    public ModelAndView userLogin(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("page/user/login");
        return modelAndView;
    }

    @RequestMapping("/index")
    public ModelAndView toIndex(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("page/search/index");
        return modelAndView;
    }

    @RequestMapping("/search")
    public ModelAndView toSearch(Blog blog){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("page/search/index");
        modelAndView.addObject("keyword",blog.getKeyword());
        modelAndView.addObject("blogList",searchFeignService.search("blog01",blog.getKeyword(),0));
        return modelAndView;
    }

}
